package cn.houserent.service;

import cn.houserent.dao.StreetDao;
import cn.houserent.pojo.Street;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;

public class StreetBiz {

    private StreetDao streetDao = new StreetDao();

    /**
     *  添加街道
     * @param street
     */
    public void addNewStreet(Street street) {
        Transaction tx = null;
        try {
            tx = streetDao.currentSession().beginTransaction();     //开启事务
            streetDao.save(street);
            tx.commit();        //提交事务
        } catch (HibernateException ex) {
            ex.printStackTrace();
            if (tx != null) {
                tx.rollback();
            }
        }
    }

    /**
     *  修改街道
     * @param street
     */
    public void updateStreet(Street street) {
        Transaction tx = null;
        try {
            tx = streetDao.currentSession().beginTransaction();     //开启事务
            streetDao.update(street);
            tx.commit();
        } catch (HibernateException ex) {
            ex.printStackTrace();
            if (tx != null) {
                tx.rollback();      //回滚事务
            }
        }
    }

    /**
     *  删除街道
     * @param street
     */
    public void deleteStreet(Street street) {
        Transaction tx = null;
        try {
            tx = streetDao.currentSession().beginTransaction();
            streetDao.delete(street);
            tx.commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            if (tx != null) {
                tx.rollback();
            }
        }
    }
}
